.class public Lcom/netease/newsreader/download/DownloadThread;
.super Ljava/lang/Thread;
.source "DownloadThread.java"


# static fields
.field private static final TAG:Ljava/lang/String; = "DownloadThread"


# instance fields
.field private block:J

.field private buffersize:I

.field private downLength:J

.field private downUrl:Ljava/net/URL;

.field private downloader:Lcom/netease/newsreader/download/FileDownloader;

.field private error:Z

.field private finish:Z

.field private pause:Z

.field private saveFile:Ljava/io/File;

.field private threadId:I


# direct methods
.method public constructor <init>(Lcom/netease/newsreader/download/FileDownloader;Ljava/net/URL;Ljava/io/File;JJI)V
    .locals 2
    .parameter "downloader"
    .parameter "downUrl"
    .parameter "saveFile"
    .parameter "block"
    .parameter "downLength"
    .parameter "threadId"

    .prologue
    const/4 v1, 0x0

    .line 27
    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    .line 19
    const/4 v0, -0x1

    iput v0, p0, Lcom/netease/newsreader/download/DownloadThread;->threadId:I

    .line 21
    iput-boolean v1, p0, Lcom/netease/newsreader/download/DownloadThread;->finish:Z

    .line 22
    iput-boolean v1, p0, Lcom/netease/newsreader/download/DownloadThread;->error:Z

    .line 23
    iput-boolean v1, p0, Lcom/netease/newsreader/download/DownloadThread;->pause:Z

    .line 25
    const/high16 v0, 0x10

    iput v0, p0, Lcom/netease/newsreader/download/DownloadThread;->buffersize:I

    .line 28
    iput-object p2, p0, Lcom/netease/newsreader/download/DownloadThread;->downUrl:Ljava/net/URL;

    .line 29
    iput-object p3, p0, Lcom/netease/newsreader/download/DownloadThread;->saveFile:Ljava/io/File;

    .line 30
    iput-wide p4, p0, Lcom/netease/newsreader/download/DownloadThread;->block:J

    .line 31
    iput-object p1, p0, Lcom/netease/newsreader/download/DownloadThread;->downloader:Lcom/netease/newsreader/download/FileDownloader;

    .line 32
    iput p8, p0, Lcom/netease/newsreader/download/DownloadThread;->threadId:I

    .line 33
    iput-wide p6, p0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    .line 34
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v0, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Lcom/netease/newsreader/download/DownloadThread;->print(Ljava/lang/String;)V

    .line 35
    return-void
.end method

.method public static getHttpResponseHeader(Ljava/net/HttpURLConnection;)Ljava/util/Map;
    .locals 4
    .parameter "http"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/net/HttpURLConnection;",
            ")",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation

    .prologue
    .line 134
    new-instance v0, Ljava/util/LinkedHashMap;

    invoke-direct {v0}, Ljava/util/LinkedHashMap;-><init>()V

    .line 135
    .local v0, header:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    const/4 v1, 0x0

    .line 136
    .local v1, i:I
    :goto_0
    invoke-virtual {p0, v1}, Ljava/net/HttpURLConnection;->getHeaderField(I)Ljava/lang/String;

    move-result-object v2

    .line 137
    .local v2, mine:Ljava/lang/String;
    if-nez v2, :cond_0

    .line 140
    return-object v0

    .line 138
    :cond_0
    invoke-virtual {p0, v1}, Ljava/net/HttpURLConnection;->getHeaderFieldKey(I)Ljava/lang/String;

    move-result-object v3

    invoke-interface {v0, v3, v2}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 135
    add-int/lit8 v1, v1, 0x1

    goto :goto_0
.end method

.method private static print(Ljava/lang/String;)V
    .locals 1
    .parameter "msg"

    .prologue
    .line 98
    const-string v0, "DownloadThread"

    invoke-static {v0, p0}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    .line 99
    return-void
.end method

.method public static printResponseHeader(Ljava/net/HttpURLConnection;)V
    .locals 6
    .parameter "http"

    .prologue
    .line 122
    invoke-static {p0}, Lcom/netease/newsreader/download/DownloadThread;->getHttpResponseHeader(Ljava/net/HttpURLConnection;)Ljava/util/Map;

    move-result-object v1

    .line 123
    .local v1, header:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    invoke-interface {v1}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v3

    invoke-interface {v3}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v4

    :goto_0
    invoke-interface {v4}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-nez v3, :cond_0

    .line 127
    return-void

    .line 123
    :cond_0
    invoke-interface {v4}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    .line 124
    .local v0, entry:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v3

    if-eqz v3, :cond_1

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Ljava/lang/String;

    invoke-static {v3}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v3

    invoke-direct {v5, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v3, ":"

    invoke-virtual {v5, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 125
    .local v2, key:Ljava/lang/String;
    :goto_1
    new-instance v5, Ljava/lang/StringBuilder;

    invoke-static {v2}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v3

    invoke-direct {v5, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Ljava/lang/String;

    invoke-virtual {v5, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {v3}, Lcom/netease/newsreader/download/DownloadThread;->print(Ljava/lang/String;)V

    goto :goto_0

    .line 124
    .end local v2           #key:Ljava/lang/String;
    :cond_1
    const-string v2, ""

    goto :goto_1
.end method


# virtual methods
.method public getDownLength()J
    .locals 2

    .prologue
    .line 118
    iget-wide v0, p0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    return-wide v0
.end method

.method public isError()Z
    .locals 1

    .prologue
    .line 111
    iget-boolean v0, p0, Lcom/netease/newsreader/download/DownloadThread;->error:Z

    return v0
.end method

.method public isFinish()Z
    .locals 1

    .prologue
    .line 105
    iget-boolean v0, p0, Lcom/netease/newsreader/download/DownloadThread;->finish:Z

    return v0
.end method

.method public pause()V
    .locals 1

    .prologue
    .line 38
    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/netease/newsreader/download/DownloadThread;->pause:Z

    .line 39
    return-void
.end method

.method public run()V
    .locals 16

    .prologue
    .line 43
    move-object/from16 v0, p0

    iget-wide v12, v0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    move-object/from16 v0, p0

    iget-wide v14, v0, Lcom/netease/newsreader/download/DownloadThread;->block:J

    cmp-long v12, v12, v14

    if-gez v12, :cond_2

    .line 44
    const/4 v5, 0x0

    .line 47
    .local v5, http:Ljava/net/HttpURLConnection;
    :try_start_0
    move-object/from16 v0, p0

    iget-object v12, v0, Lcom/netease/newsreader/download/DownloadThread;->downUrl:Ljava/net/URL;

    invoke-virtual {v12}, Ljava/net/URL;->openConnection()Ljava/net/URLConnection;

    move-result-object v12

    move-object v0, v12

    check-cast v0, Ljava/net/HttpURLConnection;

    move-object v5, v0

    .line 48
    const/16 v12, 0x7530

    invoke-virtual {v5, v12}, Ljava/net/HttpURLConnection;->setConnectTimeout(I)V

    .line 49
    const-string v12, "GET"

    invoke-virtual {v5, v12}, Ljava/net/HttpURLConnection;->setRequestMethod(Ljava/lang/String;)V

    .line 50
    const-string v12, "Accept"

    const-string v13, "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"

    invoke-virtual {v5, v12, v13}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 51
    const-string v12, "Accept-Language"

    const-string v13, "zh-CN"

    invoke-virtual {v5, v12, v13}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 52
    const-string v12, "Referer"

    move-object/from16 v0, p0

    iget-object v13, v0, Lcom/netease/newsreader/download/DownloadThread;->downUrl:Ljava/net/URL;

    invoke-virtual {v13}, Ljava/net/URL;->toString()Ljava/lang/String;

    move-result-object v13

    invoke-virtual {v5, v12, v13}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 53
    const-string v12, "Charset"

    const-string v13, "UTF-8"

    invoke-virtual {v5, v12, v13}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 54
    move-object/from16 v0, p0

    iget-wide v12, v0, Lcom/netease/newsreader/download/DownloadThread;->block:J

    move-object/from16 v0, p0

    iget v14, v0, Lcom/netease/newsreader/download/DownloadThread;->threadId:I

    add-int/lit8 v14, v14, -0x1

    int-to-long v14, v14

    mul-long/2addr v12, v14

    move-object/from16 v0, p0

    iget-wide v14, v0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    add-long v9, v12, v14

    .line 55
    .local v9, startPos:J
    move-object/from16 v0, p0

    iget-wide v12, v0, Lcom/netease/newsreader/download/DownloadThread;->block:J

    move-object/from16 v0, p0

    iget v14, v0, Lcom/netease/newsreader/download/DownloadThread;->threadId:I

    int-to-long v14, v14

    mul-long/2addr v12, v14

    const-wide/16 v14, 0x1

    sub-long v3, v12, v14

    .line 56
    .local v3, endPos:J
    const-string v12, "Range"

    new-instance v13, Ljava/lang/StringBuilder;

    const-string v14, "bytes="

    invoke-direct {v13, v14}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v13, v9, v10}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v13

    const-string v14, "-"

    invoke-virtual {v13, v14}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v13

    invoke-virtual {v13, v3, v4}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v13

    invoke-virtual {v13}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v13

    invoke-virtual {v5, v12, v13}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 57
    const-string v12, "User-Agent"

    const-string v13, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"

    invoke-virtual {v5, v12, v13}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 58
    const-string v12, "Connection"

    const-string v13, "Keep-Alive"

    invoke-virtual {v5, v12, v13}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 60
    invoke-virtual {v5}, Ljava/net/HttpURLConnection;->getResponseCode()I

    move-result v8

    .line 62
    .local v8, rspncode:I
    const/16 v12, 0xce

    if-ne v8, v12, :cond_1

    .line 63
    invoke-virtual {v5}, Ljava/net/HttpURLConnection;->getInputStream()Ljava/io/InputStream;

    move-result-object v6

    .line 64
    .local v6, inStream:Ljava/io/InputStream;
    move-object/from16 v0, p0

    iget v12, v0, Lcom/netease/newsreader/download/DownloadThread;->buffersize:I

    new-array v1, v12, [B

    .line 65
    .local v1, buffer:[B
    const/4 v7, 0x0

    .line 67
    .local v7, offset:I
    new-instance v11, Ljava/io/RandomAccessFile;

    move-object/from16 v0, p0

    iget-object v12, v0, Lcom/netease/newsreader/download/DownloadThread;->saveFile:Ljava/io/File;

    const-string v13, "rwd"

    invoke-direct {v11, v12, v13}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 68
    .local v11, threadfile:Ljava/io/RandomAccessFile;
    invoke-virtual {v11, v9, v10}, Ljava/io/RandomAccessFile;->seek(J)V

    .line 70
    :goto_0
    invoke-virtual {v6, v1}, Ljava/io/InputStream;->read([B)I

    move-result v7

    const/4 v12, -0x1

    if-eq v7, v12, :cond_0

    move-object/from16 v0, p0

    iget-boolean v12, v0, Lcom/netease/newsreader/download/DownloadThread;->pause:Z

    if-eqz v12, :cond_3

    .line 79
    :cond_0
    invoke-virtual {v11}, Ljava/io/RandomAccessFile;->close()V

    .line 80
    invoke-virtual {v6}, Ljava/io/InputStream;->close()V

    .line 83
    .end local v1           #buffer:[B
    .end local v6           #inStream:Ljava/io/InputStream;
    .end local v7           #offset:I
    .end local v11           #threadfile:Ljava/io/RandomAccessFile;
    :cond_1
    const/4 v12, 0x1

    move-object/from16 v0, p0

    iput-boolean v12, v0, Lcom/netease/newsreader/download/DownloadThread;->finish:Z

    .line 84
    new-instance v12, Ljava/lang/StringBuilder;

    const-string v13, "Thread "

    invoke-direct {v12, v13}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, p0

    iget v13, v0, Lcom/netease/newsreader/download/DownloadThread;->threadId:I

    invoke-virtual {v12, v13}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v12

    const-string v13, " is Finish. Code="

    invoke-virtual {v12, v13}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v12

    invoke-virtual {v12, v8}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v12

    invoke-virtual {v12}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v12

    invoke-static {v12}, Lcom/netease/newsreader/download/DownloadThread;->print(Ljava/lang/String;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 90
    if-eqz v5, :cond_2

    .line 91
    invoke-virtual {v5}, Ljava/net/HttpURLConnection;->disconnect()V

    .line 96
    .end local v3           #endPos:J
    .end local v5           #http:Ljava/net/HttpURLConnection;
    .end local v8           #rspncode:I
    .end local v9           #startPos:J
    :cond_2
    :goto_1
    return-void

    .line 71
    .restart local v1       #buffer:[B
    .restart local v3       #endPos:J
    .restart local v5       #http:Ljava/net/HttpURLConnection;
    .restart local v6       #inStream:Ljava/io/InputStream;
    .restart local v7       #offset:I
    .restart local v8       #rspncode:I
    .restart local v9       #startPos:J
    .restart local v11       #threadfile:Ljava/io/RandomAccessFile;
    :cond_3
    const/4 v12, 0x0

    :try_start_1
    invoke-virtual {v11, v1, v12, v7}, Ljava/io/RandomAccessFile;->write([BII)V

    .line 72
    move-object/from16 v0, p0

    iget-wide v12, v0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    int-to-long v14, v7

    add-long/2addr v12, v14

    move-object/from16 v0, p0

    iput-wide v12, v0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    .line 73
    move-object/from16 v0, p0

    iget-object v12, v0, Lcom/netease/newsreader/download/DownloadThread;->downloader:Lcom/netease/newsreader/download/FileDownloader;

    move-object/from16 v0, p0

    iget v13, v0, Lcom/netease/newsreader/download/DownloadThread;->threadId:I

    move-object/from16 v0, p0

    iget-wide v14, v0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    invoke-virtual {v12, v13, v14, v15}, Lcom/netease/newsreader/download/FileDownloader;->update(IJ)V

    .line 75
    move-object/from16 v0, p0

    iget-object v12, v0, Lcom/netease/newsreader/download/DownloadThread;->downloader:Lcom/netease/newsreader/download/FileDownloader;

    invoke-virtual {v12, v7}, Lcom/netease/newsreader/download/FileDownloader;->append(I)V

    .line 76
    const-wide/16 v12, 0x64

    invoke-static {v12, v13}, Lcom/netease/newsreader/download/DownloadThread;->sleep(J)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto :goto_0

    .line 86
    .end local v1           #buffer:[B
    .end local v3           #endPos:J
    .end local v6           #inStream:Ljava/io/InputStream;
    .end local v7           #offset:I
    .end local v8           #rspncode:I
    .end local v9           #startPos:J
    .end local v11           #threadfile:Ljava/io/RandomAccessFile;
    :catch_0
    move-exception v2

    .line 87
    .local v2, e:Ljava/lang/Exception;
    const-wide/16 v12, -0x1

    :try_start_2
    move-object/from16 v0, p0

    iput-wide v12, v0, Lcom/netease/newsreader/download/DownloadThread;->downLength:J

    .line 88
    new-instance v12, Ljava/lang/StringBuilder;

    const-string v13, "Thread "

    invoke-direct {v12, v13}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, p0

    iget v13, v0, Lcom/netease/newsreader/download/DownloadThread;->threadId:I

    invoke-virtual {v12, v13}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v12

    const-string v13, ":"

    invoke-virtual {v12, v13}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v12

    invoke-virtual {v12, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v12

    invoke-virtual {v12}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v12

    invoke-static {v12}, Lcom/netease/newsreader/download/DownloadThread;->print(Ljava/lang/String;)V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 90
    if-eqz v5, :cond_2

    .line 91
    invoke-virtual {v5}, Ljava/net/HttpURLConnection;->disconnect()V

    .line 92
    const/4 v5, 0x0

    goto :goto_1

    .line 89
    .end local v2           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v12

    .line 90
    if-eqz v5, :cond_4

    .line 91
    invoke-virtual {v5}, Ljava/net/HttpURLConnection;->disconnect()V

    .line 92
    const/4 v5, 0x0

    .line 94
    :cond_4
    throw v12
.end method
